use serde_derive::{Serialize, Deserialize};
use rust_admin2_common::{
    models::{UserAccountRow as ModelRow},
    json::JsonPager
};
use sqlx::{postgres::{PgRow}, row::Row,};
use num_traits::cast::ToPrimitive;
use crate::common::{Pool, models::BackendModel};

#[derive(Serialize, Deserialize, Debug)]
pub struct UserAccount;

impl BackendModel<ModelRow> for UserAccount {

    const TABLE_NAME: &'static str = "user_accounts";
    const FIELDS: &'static str = "id, user_id, user_name, frozen, remain, total, total_in, total_out";

    fn get_row_filter(r: &PgRow) -> ModelRow {
        unfold_fields!(r, {
            id => i32,
            user_id => i32,
            user_name => String,
        }, {frozen, remain, total, total_in, total_out,})
    }
}

impl UserAccount { 
    record_list!();
}
